import {validateStr} from '@/util/validate'

const validateString = (rule, value, callback) => {
  if (validateStr(value)[0]) {
    callback(new Error(validateStr(value)[1]))
  } else {
    callback()
  }
}

export const tableOption = {
  border: true,
  index: true,
  indexLabel: '序号',
  stripe: true,
  menuAlign: 'center',
  align: 'center',
  refreshBtn: false,
  delBtn: false,
  editBtn: false,
  showClomnuBtn: false,
  searchMenuSpan: 6,
  searchSize: 'mini',
  column: [{
    label: '类型',
    prop: 'type',
    'search': true,
    editDisabled: true,
    maxlength: 20,
    showWordLimit: true,
    rules: [{
      required: true,
      message: '请输入字典类型',
      trigger: 'blur'
    }, {
      validator: validateString,
      trigger: 'blur'
    }]
  }, {
    label: '描述',
    prop: 'description',
    'search': true,
    maxlength: 50,
    showWordLimit: true,
    rules: [{
      required: true,
      message: '请输入字典描述',
      trigger: 'blur'
    }]
  }, {
    label: '字典类型',
    prop: 'systemFlag',
    type: 'select',
    editDisabled: true,
    addDisabled: true,
    value: '0',
    dicUrl: '/admin/dict/type/dict_type',
    // addDisabled: true,
    // editDisabled: true,
    rules: [{
      required: true,
      message: '请选择字典类型',
      trigger: 'blur'
    }],
    search: true
  }, {
    label: '备注信息',
    prop: 'remarks',
    maxlength: 50,
    showWordLimit: true,
  }, {
    width: 150,
    label: '创建时间',
    prop: 'createTime',
    type: 'datetime',
    addDisplay: false,
    editDisabled: true,
    format: 'yyyy-MM-dd HH:mm',
    valueFormat: 'yyyy-MM-dd HH:mm:ss'
  }]
}

export const tableDictItemOption = {
  border: true,
  index: true,
  indexLabel: '序号',
  stripe: true,
  menuAlign: 'center',
  addBtn: false,
  delBtn: false,
  editBtn: false,
  align: 'center',
  refreshBtn: false,
  showClomnuBtn: false,
  searchSize: 'mini',
  column: [{
    label: '类型',
    prop: 'type',
    addDisabled: true,
    editDisabled: true
  }, {
    width: 150,
    label: '数据值',
    prop: 'value',
    maxlength: 20,
    showWordLimit: true,
    rules: [{
      required: true,
      message: '请输入数据值',
      trigger: 'blur'
    }, {
      validator: validateString,
      trigger: 'blur'
    }]
  }, {
    label: '标签名',
    prop: 'label',
    maxlength: 20,
    showWordLimit: true,
    rules: [{
      required: true,
      message: '请输入标签名',
      trigger: 'blur'
    }]
  }, {
    label: '描述',
    prop: 'description',
    maxlength: 50,
    showWordLimit: true,
    rules: [{
      required: true,
      message: '请输入字典描述',
      trigger: 'blur'
    }]
  }, {
    label: '排序',
    prop: 'sort',
    type: 'number',
    minRows: 0,
    maxRows: 999,
    rules: [{
      required: true,
      message: '请输入排序',
      trigger: 'blur'
    }]
  }, {
    label: '备注信息',
    prop: 'remarks',
    maxlength: 50,
    showWordLimit: true,
  }]
}
